<template>
  <view class="container">
		<nav-ber :title="'我的积分'" :bgColor="'#f7f8ff'"></nav-ber>
		<view class="u-search-flex">
			积分余额：{{ integral }}
		</view>
		<view style="padding: 0 20rpx;box-sizing: border-box;">
			<u-subsection  @change="sectionChange" :list="list" mode="subsection" :current="current"></u-subsection>
		</view>
		<u-empty style="margin-top: 100rpx;" v-if="!finIntegrallist.length" text="暂无数据" mode="list">
		</u-empty>
		<view class="province">
			<scroll-view scroll-y="true" style="height: 100%" bindscrolltoupper="upper" @scrolltolower="lower" :lower-threshold="300">
			<view v-if="current == 1">
				<view class="items_box" v-for="(item, index) in finIntegrallist" :key="index">
					<view class="img_flex">
						<view>
							<view class="font_w">
								<span class="w_100">流水号：</span>
								<span style="flex: 1;">P21321312 </span>
							</view>
							<view class="font_w">
								<span class="w_100">核销积分：</span>
								<span style="flex: 1;">{{ item.changeIntegral }} </span>
							</view>
							<view class="font_w">
								<span class="w_100">核销人：</span>
								<span style="flex: 1;">{{ item.createBy }} </span>
							</view>
							<view class="font_w">
								<span class="w_100">任务时间：</span>
								<span style="flex: 1;">{{ item.createTime }} </span>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view  v-if="current == 0">
				<view class="items_box" v-for="(item, index) in finIntegrallist" :key="index">
					<view class="img_flex">
						<view>
							<view class="font_w">
								<span class="w_100">任务名称：</span>
								<span style="flex: 1;">{{ item.taskName }} </span>
							</view>
							<!-- <view class="font_w">
								<span class="w_100">医院：</span>
								<span style="flex: 1;">{{  }} </span>
							</view> -->
							<!-- <view class="font_w">
								<span class="w_100">医生：</span>
								<span style="flex: 1;">李医生 </span>
							</view> -->
							<view class="font_w">
								<span class="w_100">任务时间：</span>
								<span style="flex: 1;">{{ item.createTime }}</span>
							</view>
							<view class="font_w">
								<span class="w_100">获得积分：</span>
								<span style="flex: 1;">{{ item.changeIntegral }} </span>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view v-if="toTheEnd" class="" style="color: gray;margin: 20rpx 0;text-align: center;font-size: 26rpx;">
				我到底了~
			</view>
			</scroll-view>
		</view>
  </view>
</template>
<script>
	import { finIntegrallistItem, finIntegralById } from '@/api/personalCenter.js'
  export default {
    data() {
			return {
				totals: 0,
				toTheEnd: false,
				pageNum: 1,
				integral: '',
				finIntegrallist: [],
				keyword: '',
				ispro: '1',
				list: ['积分增加记录', '积分核销记录'],
				current: 0,
			}
    },
		onLoad() {
			this.finIntegrallistItemFun()
			this.finIntegralByIdFun()
		},
		methods: {
			lower(e) {
				if (this.finIntegrallist.length >= this.totals) {
					this.toTheEnd = true
					return
				}
				if (!this.finIntegrallist.length) {
					this.toTheEnd = false
				}
				this.pageNum = this.pageNum+1
				this.finIntegrallistItemFun()
			},
			finIntegralByIdFun() {
				finIntegralById(JSON.parse(uni.getStorageSync('userInfoRole')).id).then((res) => {
					this.integral = res.data.integral
				})
			},
			finIntegrallistItemFun() {
				finIntegrallistItem({
					pageNum: this.pageNum,
					pageSize: 10,
					integralType: this.current,
					id: JSON.parse(uni.getStorageSync('userInfoRole')).id,
					type: JSON.parse(uni.getStorageSync('userInfo')).userType == '02'? 0 : 1	
				}).then((res) => {
					// console.log(res)
					// this.finIntegrallist = res.rows
					this.finIntegrallist = [...this.finIntegrallist, ...res.rows]
					this.totals = res.total
				})
			},
			goTovixFun(type) {
				// uni.navigateTo({
				// 	url:type == 1? "/pages/task/researchTask/index" : "/pages/task/visitTask/index"
				// })
			},
			proFun(val) {
				this.ispro = val
			},
			sectionChange(index) {
				this.current = index;
				this.pageNum = 1
				this.finIntegrallist = []
				this.finIntegrallistItemFun()
			},
			goToRequestFun(type) {
				uni.navigateTo({
					url:type == 1? "/pages/task/research/index" : "/pages/task/taskRequest/index"
				})
			},
		}
  }
</script>
<style lang="scss" scoped>
	.sea_pad {
		padding: 0 30rpx;
		box-sizing: border-box;
	}
	.container {
		background-color: #f7f8ff;
		// background-color: #fff;
		display: flex;
		flex-direction: column;
		height: 100vh;
		overflow: hidden;
	}
	.province {
		flex: 1;
		overflow: hidden;
		padding: 0 20rpx;
		margin-top: 20rpx;
	}
	.pro_list {
		padding: 20rpx 50rpx;
		box-sizing: border-box;
	}
	.pro_list_is {
		background-color: #f7f8ff;
		color: #2979ff;
		position: relative;
	}
	.pro_list_is::before {
		content: '';
		display: block;
		width: 10rpx;
		height: 50rpx;
		background-color: #2979ff;
		position: absolute;
		left: -20rpx;
	}
	.u-search-flex {
		display: flex;
		align-items: center;
		padding: 20rpx;
		box-sizing: border-box;
	}
	.addr_font {
		color: gray;
		font-size: 25rpx;
		margin: 0 10rpx;
		margin-right: 20rpx;
	}
	.chat_left {
		margin-left: 20rpx;
	}
	.items_box {
		background-color: #fff;
		padding: 20rpx;
		border-radius: 20rpx;
		margin-bottom: 20rpx;
		.time_flex {
			display: flex;
			align-items: center;
			justify-content: space-between;
			color: #111;
			.mar_20 {
				margin: 15rpx 0;
			}
		}
		.font_w {
			// font-weight: 900;
			color: #111;
			display: flex;
			// align-items: center;
			margin: 20rpx 0;
		}
		.button_color {
			background-color: #2979ff;
			color: #fff;
			padding: 15rpx 40rpx;
			box-sizing: border-box;
			border-radius: 100rpx;
		}
	}
	.img_flex {
		display: flex;
		align-items: center;
	}
	.w_100 {
		display: inline-block;
		width: 200rpx;
		text-align: right;
	}
</style>
